<?php
return [
    'module' => [
        'name' => 'product',
        'title' => '商品管理',
        'table' => 'products',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '商品ID',
            'primary' => true,
            'auto_increment' => true,
            'nullable' => false,
            'required' => true,
        ],
        'category_id' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '分类ID',
            'required' => true,
            'nullable' => false,
        ],
        'title' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '商品标题',
            'required' => true,
            'nullable' => false,
        ],
        'description' => [
            'type' => 'text',
            'comment' => '商品描述',
            'nullable' => true,
        ],
        'image' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '商品主图',
            'required' => true,
            'nullable' => false,
        ],
        'images' => [
            'type' => 'json',
            'comment' => '商品图片集',
            'nullable' => true,
        ],
        'price' => [
            'type' => 'decimal',
            'length' => '10,2',
            'comment' => '商品价格',
            'required' => true,
            'nullable' => false,
        ],
        'stock' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '库存数量',
            'required' => true,
            'nullable' => false,
            'default' => 0,
        ],
        'sales' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '销量',
            'nullable' => false,
            'default' => 0,
        ],
        'is_on_sale' => [
            'type' => 'tinyint',
            'length' => 1,
            'comment' => '是否上架',
            'nullable' => false,
            'default' => 0,
            'options' => [
                0 => '下架',
                1 => '上架'
            ],
        ],
        'sort' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '排序',
            'nullable' => false,
            'default' => 0,
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
            'extra' => 'ON UPDATE CURRENT_TIMESTAMP'
        ],
    ],
    
    'relations' => [
        'category' => [
            'type' => 'belongsTo',
            'model' => 'ProductCategory',
            'foreign_key' => 'category_id',
        ],
        'skus' => [
            'type' => 'hasMany',
            'model' => 'ProductSku',
            'foreign_key' => 'product_id',
        ],
    ],
    
    'queries' => [
        'title' => ['like', '%?%'],
        'category_id' => ['=', '?'],
        'price' => ['between', '?,?'],
        'is_on_sale' => ['=', '?'],
    ],
]; 